/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.qudexapps.xmllib.model;

import java.io.Serializable;

import org.apache.http.Header;

/**
 * Class to results information when generating new graphs in Mulgara with the
 * extra Metadata annotations: Qudex, DDI
 * 
 * @author agustinamartinez
 * 
 */
public class GraphInformation implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 9195308685473752927L;
    /**
     * Number of statements added into the graph
     */
    private int numberStatements;
    /**
     * Updated graph name
     */
    private String graphName;
    /**
     * Description of the updated graph
     */
    private String graphDescription;
    /**
     * Fedora PID of the statements source object
     */
    private String sourceObjectId;
    /**
     * Fedora datastream name of the object source of the RDF statements
     */
    private String dsName;
    
    // GETTERS AND SETTERS
    public void setNumberStatements(int numberStatements) {
	this.numberStatements = numberStatements;
    }

    public int getNumberStatements() {
	return numberStatements;
    }

    public void setGraphName(String graphName) {
	this.graphName = graphName;
    }

    public String getGraphName() {
	return graphName;
    }

    public void setGraphDescription(String graphDescription) {
	this.graphDescription = graphDescription;
    }

    public String getGraphDescription() {
	return graphDescription;
    }
    
    /**
     * @param sourceObjectId
     *            the sourceObjectId to set
     */
    public void setSourceObjectId(String sourceObjectId) {
	this.sourceObjectId = sourceObjectId;
    }

    /**
     * @return the sourceObjectId
     */
    public String getSourceObjectId() {
	return sourceObjectId;
    }

    /**
     * @param dsName
     *            the dsName to set
     */
    public void setDsName(String dsName) {
	this.dsName = dsName;
    }

    /**
     * @return the dsName
     */
    public String getDsName() {
	return dsName;
    }
    /**
     * Custom constructor
     * 
     * @param graphName updated graph name
     * @param headersArray headers array with results of the operations in Mulgara
     */
    public GraphInformation(String graphName, Header[] headersArray) {

	this.setGraphName(graphName);
	Header header = findHeader("Statements-Loaded", headersArray);
	if (header != null) {
	    try {
		this.setNumberStatements(Integer.parseInt(header.getValue()));
	    } catch (NumberFormatException ex) {
		ex.printStackTrace();
	    }
	}
    }
    /**
     * Find a particular header instance in the headers array
     * @param headerName header name to search
     * @param headersArray array of response headers
     * @return
     */
    private Header findHeader(String headerName, Header[] headersArray) {
	for (Header header : headersArray) {
	    if (header.getName().equalsIgnoreCase(headerName))
		return header;
	}
	// header not found
	return null;
    }
}
